class Signaling {
  url;
  ws;
  name;
  onmessage
  constructor(url, onmessage) {
    this.url = url;
    this.name = "it's me";
    this.onmessage = onmessage
  }

  start() {
    return new Promise((resolve, reject) => {
      console.info("this.name:", this.name);
        this.ws = new WebSocket(this.url);
        this.ws.addEventListener("open", (event) => {
          resolve(event);
        });
        this.ws.addEventListener("error", (event) => {
            console.info("error", event);
            reject(event);
        });
        this.ws.addEventListener("message", this.onmessage)
    });
  }


  sendMessage(To, Type, Data) {
    console.log("send to: ", To)
    this.ws.send(JSON.stringify({To, Type, Data}))
  }
}